<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.




 */
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.controller');
jimport('joomla.filter.filterinput');

class lrControllerEditcss extends lrController
{
	function __construct()
	{
		parent::__construct();
		
		$this->registerTask( 'apply', 'save' );
		
	}
 	
	function save()
	{
	$task=JRequest::getvar('task');
	$filecontent=JRequest::getvar('filecontent');
	$css_file=JRequest::getvar('css_file');
	$file = JPATH_COMPONENT_SITE.DS.'assets'.DS.'css'.DS.$css_file;
	//saving
		jimport('joomla.filesystem.file');
		$returnid = JFile::write($file, $filecontent);
	
		$returnid = true;
		
		if ($returnid) {

			switch ($task)
			{
				case 'apply' :
					$link = 'index.php?option=com_lr&controller=settings&task=edit_css&css_file='.$css_file;
					break;

				default :
					$link = 'index.php?option=com_lr&controller=settings&view=settings&task=edit';
					break;
			}
			$msg	= JText::_( 'CSS SAVED');

			$cache = &JFactory::getCache('com_lr');
			$cache->clean();

		} else {

			$msg 	= '';
			$link = 'index.php?option=com_lr&view=settings';

		}
		$this->setRedirect( $link, $msg );
	 	}
	 	
	 	function cancel()
		{
		// Check for request forgeries
		JRequest::checkToken() or die( 'Invalid Token' );

		$this->setRedirect( 'index.php?option=com_lr&view=settings' );
		}
	 	
}
?>